<template>
    <div>
        <div>
            <mt-header title="贷款返校校验码">
                <router-link to="/" slot="left">
                    <mt-button icon="back">返回</mt-button>
                </router-link>
                <mt-button icon="more" slot="right"></mt-button>
            </mt-header>
        </div>
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh" style="height: 900px">
            <el-card style="border-radius: 14px; margin-top: 10px; width: 360px; margin-left: 6px" class="box-card">
                <div slot="header" class="clearfix">
                    <van-tag color="#7232dd">本年度返校校验码</van-tag>
                    <van-badge style="float: right; padding: 3px 0" :content="creditList.length">
                        <el-button style="float: right; padding: 3px 0" type="text">贷款次数</el-button>
                    </van-badge>
                </div>
                <van-collapse v-model="activeNames">
                    <van-collapse-item v-for="(item, index) in creditList" :key="index" :title="item.duringYear + '的贷款返校校验码'" name="1">
                        <van-tag v-if="item.rebackCode" color="#7232dd" type="primary" plain >{{ item.rebackCode }}</van-tag>
                        <van-tag v-else color="#7232dd" type="primary" plain >您在本年度还没收到返校校验码</van-tag>
                    </van-collapse-item>
                </van-collapse>
            </el-card>
        </van-pull-refresh>
    </div>
</template>

<script>
    import Toast from "vant/lib/toast";
    import axios from "axios";

    export default {
        name: "Reback",
        data() {
            return {
                creditList: [],
                isLoading: false,
                activeNames: ['1'],
            };
        },
        created() {
            this.InitCreditList()
        },
        methods: {
            InitCreditList() {
                axios.get('http://localhost:8080/system/user/profile',
                    {
                        headers: { Authorization: sessionStorage.getItem('token')}
                    }).then(res => {
                    this.user = res.data.data
                    axios.get('http://localhost:8080/student/credit/data/name/' + this.user.userName,
                        {
                            headers: { Authorization: sessionStorage.getItem('token')}
                        }).then(res => {
                        console.log(res.data.data)
                        this.creditList = res.data.data
                    })

                })

            },
            onRefresh() {
                setTimeout(() => {
                    Toast('刷新成功');
                    this.isLoading = false;
                    this.count++;
                }, 1000);
            },
        }
    }
</script>

<style scoped>

</style>
